package web.mb;

import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import metier.entities.SubCategorie;
import metier.entities.categorie;
import metier.sess.ICategorieLocal;
import metier.sess.ISubCategorieLocal;


@ManagedBean
@RequestScoped
public class SubCategoryMB {
	@EJB
	private ISubCategorieLocal metier;
	
	@EJB
	private ICategorieLocal metierc;
	
	private SubCategorie subcat=new SubCategorie();
	private Integer idCat;
	private Integer Id;

	
	
	public String Ajouter()
	{
		
		
		categorie cat=metierc.getCategorie(idCat);
		subcat.setCategorie(cat);
		metier.addSubCategorie(subcat);
		return "ManageSubCategory.xhtml";
	}
	
	
	
	
	public String edit(Integer Id)
	{
		this.Id=Id;
		this.subcat=metier.getSubCategorie(Id);
		this.idCat=subcat.getCategorie().getIdCategorie();
		return "EditSubCategory.xhtml";
	}
	
	public String Modifier()
	{
		SubCategorie c=metier.getSubCategorie(Id);
		c.setIntitule(subcat.getIntitule());
		c.setStatut(subcat.getStatut());
		c.setCategorie(metierc.getCategorie(idCat));
		metier.updateSubCategories(c);
		return "ManageSubCategory.xhtml";
	}

	public String Supprimer(Integer Id)
	{
		
		metier.deleteSubCategorie(Id);
		return "succes";
		
	}
	
	
	
	public List<SubCategorie> getListSubCategorie()
	{
		return metier.getAllSubCategories();
	}
	
	public List<categorie> getListCategorie()
	{
		return metierc.getAllCategoriesActive();
	}
	 
	

	public Integer getId() {
		return Id;
	}

	public void setId(Integer id) {
		Id = id;
	}




	public ISubCategorieLocal getMetier() {
		return metier;
	}




	public void setMetier(ISubCategorieLocal metier) {
		this.metier = metier;
	}




	public SubCategorie getSubcat() {
		return subcat;
	}


	public void setSubcat(SubCategorie subcat) {
		this.subcat = subcat;
	}




	public Integer getIdCat() {
		return idCat;
	}




	public void setIdCat(Integer idCat) {
		this.idCat = idCat;
	}

	

}
